package com.platform.modules.mch.controller;

import com.platform.common.utils.RestResponse;
import com.platform.common.utils.mch.InputDataDecode;
import com.platform.modules.mch.dto.callback.*;
import com.platform.modules.mch.service.MchCallBackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/mch/callBack")
public class MchCallBackController {

    @Resource
    private MchCallBackService callBackService;

    @PostMapping("orderUpdate")
    public RestResponse orderUpdate(@RequestBody InputDataDecode dataDecode) {
        log.info("-------订单状态更新通知----------");
        callBackService.orderUpdate(dataDecode.getParams(MchOrderInfoDto.class));
        return RestResponse.success();
    }

    @PostMapping("goodsIsOnSaleChange")
    public RestResponse goodsIsOnSaleChange(@RequestBody InputDataDecode dataDecode) {
        log.info("-------商品上下架通知----------");
        callBackService.goodsIsOnSaleChange(dataDecode.getParams(MchGoodsStatusChangeDto.class));
        return RestResponse.success();
    }

    @PostMapping("productLocationStatusChange")
    public RestResponse productLocationStatusChange(@RequestBody InputDataDecode dataDecode) {
        log.info("-------商品站点上下架通知----------");
        callBackService.productLocationStatusChange(dataDecode.getParams(MchProLocStatusChangeDto.class));
        return RestResponse.success();
    }

    @PostMapping("cancelAfterVerification")
    public RestResponse cancelAfterVerification(@RequestBody InputDataDecode dataDecode) {
        log.info("-------订单核销通知----------");
        callBackService.cancelAfterVerification(dataDecode.getParams(MchVerificationDto.class));
        return RestResponse.success();
    }

    @PostMapping("orderRefund")
    public RestResponse orderRefund(@RequestBody InputDataDecode dataDecode) {
        log.info("-------订单退款通知----------");
        callBackService.orderRefund(dataDecode.getParams(MchOrderRefundDto.class));
        return RestResponse.success();
    }

}
